home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / Kamprath's CDEF Pack ƒ / CDEF Sampler Program ƒ / samplerControls.c < prev    next >
C/C++ Source or Header  |  1994-05-21  |  5KB  |  265 lines

  1. #include "samplerControls.h"
  2. #include "number_picker.h"
  3.  
  4. ControlHandle        rocketCntl, timeButtonCntl, timeCntl, dateCntl, numberCntl;
  5. DateTimeRec            *theTime;
  6.  
  7. extern WindowPtr    samplerWindow;
  8.  
  9. void  SetUpWindowCntls( void )
  10. {
  11. Rect    ctrlRect;
  12.  
  13.     SetRect(&ctrlRect, 5,15,37,47);
  14.     rocketCntl = NewControl( samplerWindow, &ctrlRect, "\p", 
  15.                 TRUE, 0, 0, 1, 1000*16 + 0, 0 );
  16.                 
  17.     SetRect(&ctrlRect, 5,55,37,87);
  18.     timeButtonCntl = NewControl( samplerWindow, &ctrlRect, "\p", 
  19.                 TRUE, 0, 0, 1, 1000*16 + 1, 0 );
  20.     
  21.     theTime = (DateTimeRec *)NewPtrClear(sizeof(DateTimeRec));
  22.     GetTime( theTime );
  23.     
  24.     SetRect(&ctrlRect, 15,95,180,115);
  25.     timeCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
  26.                             0, 0, 128, 16*1001 + kTimeVariation, 
  27.                             (long)(theTime));
  28.  
  29.     SetRect(&ctrlRect, 15,120,180,140);
  30.     dateCntl = NewControl( samplerWindow, &ctrlRect, "\pTime Control", TRUE,
  31.                             0, 0, 128, 16*1001 + kDateVariation, 
  32.                             (long)(theTime));
  33.  
  34.     SetRect(&ctrlRect, 5,145,155,165);
  35.     numberCntl = NewControl( samplerWindow, &ctrlRect, "\pNumber Control:", TRUE,
  36.                             0, 0, 5000, 16*1002 + 0, 0);
  37. }
  38.  
  39. pascal void NumCDEFProc(ControlHandle theControl, short theCode)
  40. {
  41. static long        lastTicks = 0;
  42.     
  43.     if (theCode == 0)
  44.         return ;
  45.     
  46.     if (TickCount() < lastTicks+10)
  47.         return;
  48.         
  49.     switch (theCode) 
  50.     {
  51.         case kNPArrowButtonUp: 
  52.             SetCtlValue( theControl, GetCtlValue(theControl)+1);
  53.             break;
  54.         case kNPArrowButtonDown: 
  55.             SetCtlValue( theControl, GetCtlValue(theControl)-1);
  56.             break;
  57.     }
  58.     
  59.     lastTicks = TickCount();
  60. }
  61.  
  62.  
  63.  
  64.  
  65. /*
  66.  * Time & Date CEF Handler routines
  67.  *
  68.  */
  69.  
  70.  
  71. long ticks, curWait;
  72.  
  73. void    HandleTimeCDEFClick(Point    where)
  74. {
  75. short            thePart, trackPart;
  76. ControlHandle    ch;
  77.  
  78.     ticks = TickCount();
  79.     curWait = 60;
  80.     trackPart = TrackControl( timeCntl, where, TimeCDEFAction);
  81.     
  82.     if (trackPart)
  83.     {
  84.         HandleTimeCDEFPart( timeCntl, trackPart);
  85.     }
  86. }
  87. void    HandleDateCDEFClick(Point    where)
  88. {
  89. short            thePart, trackPart;
  90. ControlHandle    ch;
  91.  
  92.     ticks = TickCount();
  93.     curWait = 60;
  94.     trackPart = TrackControl( dateCntl, where, DateCDEFAction);
  95.     
  96.     if (trackPart)
  97.     {
  98.         HandleDateCDEFPart( dateCntl, trackPart);
  99.     }
  100. }
  101.  
  102. pascal void TimeCDEFAction( ControlHandle ch, short part)
  103. {
  104.     if (TickCount() >= ticks + curWait)
  105.     {
  106.         HandleTimeCDEFPart( ch, part);
  107.         ticks = TickCount();
  108.         curWait = 15;
  109.     }
  110. }
  111. pascal void DateCDEFAction( ControlHandle ch, short part)
  112. {
  113.     if (TickCount() >= ticks + curWait)
  114.     {
  115.         HandleDateCDEFPart( ch, part);
  116.         ticks = TickCount();
  117.         curWait = 15;
  118.     }
  119. }
  120.  
  121. void HandleTimeCDEFPart( ControlHandle ch, short part)
  122. {
  123. DateTimeRec        *theTime;
  124. unsigned long    timeNum;
  125.  
  126.     switch (part)
  127.     {
  128.         case kHourItem:
  129.             SetCtlValue( ch, kHourItem);
  130.             break;
  131.         case kMinItem:
  132.             SetCtlValue( ch, kMinItem);
  133.             break;
  134.         case kAMPMItem:
  135.             SetCtlValue( ch, kAMPMItem);
  136.             break;
  137.         case kArrowButtonUp:
  138.             theTime = (DateTimeRec *)GetCRefCon(ch);
  139.             switch (GetCtlValue(ch))
  140.             {
  141.                 case kHourItem:
  142.                     if (theTime->hour < 23)
  143.                     {
  144.                         (theTime->hour)++;
  145.                     }
  146.                     break;
  147.                 case kMinItem:
  148.                     if (theTime->minute < 59)
  149.                     {
  150.                         (theTime->minute)++;
  151.                     }
  152.                     break;
  153.                 case kAMPMItem:
  154.                     if ( (theTime->hour + 12) <= 23)
  155.                     {
  156.                         (theTime->hour)  += 12;
  157.                     }
  158.                     break;
  159.             }
  160.             Draw1Control( ch );
  161.             break;
  162.         case kArrowButtonDown:
  163.             theTime = (DateTimeRec *)GetCRefCon(ch);
  164.             switch (GetCtlValue(ch))
  165.             {
  166.                 case kHourItem:
  167.                     if (theTime->hour > 0)
  168.                     {
  169.                         (theTime->hour)--;
  170.                     }
  171.                     break;
  172.                 case kMinItem:
  173.                     if (theTime->minute > 0)
  174.                     {
  175.                         (theTime->minute)--;
  176.                     }
  177.                     break;
  178.                 case kAMPMItem:
  179.                     if ( (theTime->hour - 12) >= 0)
  180.                     {
  181.                         (theTime->hour)  -= 12;
  182.                     }
  183.                     break;
  184.             }
  185.             Draw1Control( ch );
  186.             break;
  187.         default:
  188.             SetCtlValue( ch, 0);
  189.             break;
  190.     }
  191. }
  192. void HandleDateCDEFPart( ControlHandle ch, short part)
  193. {
  194. DateTimeRec        *theTime;
  195. unsigned long    timeNum;
  196.     switch (part)
  197.     {
  198.         case kMonthItem:
  199.             SetCtlValue( ch, kMonthItem);
  200.             break;
  201.         case kDateItem:
  202.             SetCtlValue( ch, kDateItem);
  203.             break;
  204.         case kYearItem:
  205.             SetCtlValue( ch, kYearItem);
  206.             break;
  207.         case kDayOfWeekItem:
  208.             SetCtlValue( ch, kDayOfWeekItem);
  209.             break;
  210.         case kArrowButtonUp:
  211.             theTime = (DateTimeRec *)GetCRefCon(ch);
  212.             switch (GetCtlValue(ch))
  213.             {
  214.                 case kMonthItem:
  215.                     if (theTime->month < 12)
  216.                     {
  217.                         (theTime->month)++;
  218.                     }
  219.                     break;
  220.                 case kDateItem:
  221.                 case kDayOfWeekItem:
  222.                     (theTime->day)++;
  223.                     Date2Secs(theTime, &timeNum);
  224.                     Secs2Date(timeNum, theTime);
  225.                     break;
  226.                 case kYearItem:
  227.                     if (theTime->year < 2040)
  228.                     {
  229.                         (theTime->year)++;
  230.                     }
  231.                     break;
  232.             }
  233.             Draw1Control( ch );
  234.             break;
  235.         case kArrowButtonDown:
  236.             theTime = (DateTimeRec *)GetCRefCon(ch);
  237.             switch (GetCtlValue(ch))
  238.             {
  239.                 case kMonthItem:
  240.                     if (theTime->month > 1)
  241.                     {
  242.                         (theTime->month)--;
  243.                     }
  244.                     break;
  245.                 case kDateItem:
  246.                 case kDayOfWeekItem:
  247.                     (theTime->day)--;
  248.                     Date2Secs(theTime, &timeNum);
  249.                     Secs2Date(timeNum, theTime);
  250.                     break;
  251.                 case kYearItem:
  252.                     if (theTime->year > 1904)
  253.                     {
  254.                         (theTime->year)--;
  255.                     }
  256.                     break;
  257.             }
  258.             Draw1Control( ch );
  259.             break;
  260.         default:
  261.             SetCtlValue( ch, 0);
  262.             break;
  263.     }
  264. }
  265.